import { Action } from '@ngrx/store';
import { Auth, User } from '../domain/index';

export enum AuthActionTypes {
    LOGIN = '[Auth] Login',
    LOGIN_SUCCESS = '[Auth] Login Success',
    LOGIN_FAIL = '[Auth] Login Fail',
    REGISTER = '[Auth] Rigister',
    REGISTER_SUCCESS = '[Auth] Rigister Success',
    REGISTER_FAIL = '[Auth] Rigister Fail',
    LOGOUT = '[Auth] Logout'
}

export class LoginAction implements Action {
    readonly type = AuthActionTypes.LOGIN;

    constructor(public payload: { email: string, password: string }) { }
}
export class LoginSuccessAction implements Action {
    readonly type = AuthActionTypes.LOGIN_SUCCESS;

    constructor(public payload: Auth) { }
}
export class LoginFailAction implements Action {
    readonly type = AuthActionTypes.LOGIN_FAIL;

    constructor(public payload: string) { }
}

export class RegisterAction implements Action {
    readonly type = AuthActionTypes.REGISTER;

    constructor(public payload: User) { }
}
export class RegisterSuccessAction implements Action {
    readonly type = AuthActionTypes.REGISTER_SUCCESS;

    constructor(public payload: Auth) { }
}
export class RegisterFailAction implements Action {
    readonly type = AuthActionTypes.REGISTER_FAIL;

    constructor(public payload: string) { }
}

export class LogoutAction implements Action {
    readonly type = AuthActionTypes.LOGOUT;

    constructor(public payload: any) { }
}

/**
 * Export a type alias of all actions in this action group
 * so that reducers can easily compose action types
 */
export type AuthActions
    = LoginAction
    | LoginSuccessAction
    | LoginFailAction
    | RegisterAction
    | RegisterSuccessAction
    | RegisterFailAction
    | LogoutAction;
